<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a correctly ordered and delimited locale ID</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="locale.canonicalize.html">« Locale::canonicalize</a></li>
      <li style="float: right;"><a href="locale.filtermatches.html">Locale::filterMatches »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.locale.html">Locale</a></li>
    <li>Returns a correctly ordered and delimited locale ID</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="locale.composelocale" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Locale::composeLocale</h1>
  <h1 class="refname">locale_compose</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Locale::composeLocale</span> -- <span class="refname">locale_compose</span> &mdash; <span class="dc-title">Returns a correctly ordered and delimited locale ID</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-locale.composelocale-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Locale::composeLocale</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$subtags</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>locale_compose</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$subtags</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Returns a correctly ordered and delimited locale ID the keys identify the
   particular locale ID subtags, and the values are the associated subtag
   values.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-locale.composelocale-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">subtags</code></dt>

     <dd>

      <p class="para">
       An <span class="type">array</span> containing a list of key-value pairs, where the keys identify
       the particular locale ID subtags, and the values are the associated
       subtag values.
       <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
         The <code class="literal">&#039;variant&#039;</code> and <code class="literal">&#039;private&#039;</code> subtags can take maximum 15 values
         whereas <code class="literal">&#039;extlang&#039;</code> can take maximum 3 values. For instance, variants are allowed
         with the suffix ranging from 0-14. Hence the keys for the input array
         can be <code class="literal">variant0</code>, <code class="literal">variant1</code>, …,<code class="literal">variant14</code>. In the returned locale id,
         the subtag is ordered by suffix resulting in <code class="literal">variant0</code> followed by
         <code class="literal">variant1</code> followed by <code class="literal">variant2</code> and so on.
        </p>
        <p class="para">
         Alternatively, the <code class="literal">&#039;variant&#039;</code>, <code class="literal">&#039;private&#039;</code> and <code class="literal">&#039;extlang&#039;</code> values can be specified
         as array under specific key (e.g. <code class="literal">&#039;variant&#039;</code>).
         In this case no limits on the number of recognized subtags apply.
        </p>
       </p></blockquote>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-locale.composelocale-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The corresponding locale identifier, or <strong><code>false</code></strong> when <code class="parameter">subtags</code> is empty.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-locale.composelocale-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2329">
   <p><strong>示例 #1 <span class="function"><strong>locale_compose()</strong></span> example</strong></p>
   <div class="example-contents">
    <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'language'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'en'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'script'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'Hans'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'region'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'CN'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'variant2'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'rozaj'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'variant1'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'nedis'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'private1'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'prv1'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'private2'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'prv2'</span><span style="color: #007700">,<br />);<br />echo&nbsp;</span><span style="color: #0000BB">locale_compose</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2330">
   <p><strong>示例 #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'language'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'en'&nbsp;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'script'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'Hans'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'region'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'CN'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'variant2'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'rozaj'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'variant1'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'nedis'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'private1'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'prv1'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'private2'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'prv2'</span><span style="color: #007700">,<br />);<br />echo&nbsp;</span><span style="color: #0000BB">Locale</span><span style="color: #007700">::</span><span style="color: #0000BB">composeLocale</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
Locale: en_Hans_CN_nedis_rozaj_x_prv1_prv2
</pre></div>
  </div>

  <div class="example" id="locale.composelocale.example.limits">
   <p><strong>示例 #3 Subtag limits</strong></p>
   <div class="example-contents"><p>
    If <code class="parameter">subtags</code> are given as separate keys with numeric suffix,
    unsupported keys are silently ignored (in this case <code class="literal">&#039;extlang3&#039;</code>),
    and ordered in the result by numeric suffix.
    There are no limits, if subtags are given as <span class="type">array</span>; the order is as given.
   </p></div>
   <div class="example-contents">
    <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'language'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'en'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'script'&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Hans'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'region'&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'CN'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'extlang3'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'d'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'extlang2'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'c'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'extlang1'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'extlang0'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'a'</span><span style="color: #007700">,<br />);<br />echo&nbsp;</span><span style="color: #0000BB">locale_compose</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'language'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'en'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'script'&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Hans'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'region'&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'CN'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'extlang'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #DD0000">'a'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'c'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'d'</span><span style="color: #007700">],<br />);<br />echo&nbsp;</span><span style="color: #0000BB">locale_compose</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
en_a_b_c_Hans_CN
en_a_b_c_d_Hans_CN
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-locale.composelocale-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="locale.parselocale.html" class="function" rel="rdfs-seeAlso">locale_parse()</a> - Returns a key-value array of locale ID subtag elements</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>